#include "bottomlightbutton.h"
#include "ui_bottomlightbutton.h"

#include <QColor>
bottomLightButton::bottomLightButton(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::bottomLightButton)
{
    ui->setupUi(this);
    initForm();
    btnsLight<<ui->widget1<<ui->widget2<<ui->widget3<<ui->widget4<<ui->widget5;

    for(int i = 0 ; i < btnsLight.count(); i++)
    {
        btnsLight.at(i)->setBgColor(QColor(197, 197, 197));
    }
}

bottomLightButton::~bottomLightButton()
{
    delete ui;
}
void bottomLightButton::initForm()
{
    type = 0;

    timer = new QTimer(this);
    timer->setInterval(1000);
    connect(timer, SIGNAL(timeout()), this, SLOT(updateValue()));
//    timer->start();
//    updateValue();
}

void bottomLightButton::updateValue()
{
    //初始化绿灯匀亮效果
    if(type < 5)
    {
//        btnsLight.at(type)->setLightGreen();
//        type++;
        type = 5;
    }
    else if(type >= 5 && type <= 10 && type % 2 == 1)
    {
        timer->setInterval(200);
        for(int i = 0; i < btnsLight.count(); i++)
        {
            btnsLight.at(i)->setGray();
        }
        type++;
    }else if(type >= 5 && type <= 10 && type % 2 == 0)
    {
        for(int i = 0; i < btnsLight.count(); i++)
        {
//            btnsLight.at(i)->setLightGreen();
            btnsLight.at(i)->setGreen();
        }
        type++;
    }
    if(type > 10)
    {
        timer->stop();
        ui->widget1->setText("料斗");
        ui->widget2->setText("吸阻");
        ui->widget3->setText("圆周");
        ui->widget4->setText("硬度");
        ui->widget5->setText("打孔");
    }
}
void bottomLightButton::startInit()
{
    isProgressOn = true;
    timer->start();
}
void bottomLightButton::setAllMachineGreen()
{
    for(int i = 0; i < btnsLight.count(); i++)
    {
        btnsLight.at(i)->setGreen();
    }
    ui->widget1->setText("料斗");
    ui->widget2->setText("吸阻");
    ui->widget3->setText("圆周");
    ui->widget4->setText("硬度");
    ui->widget5->setText("打孔");
}
void bottomLightButton::setOneMachineErrro(int Num, QString msg)
{
//    for(int i = 0; i < btnsLight.count(); i++)
    {
        btnsLight.at(Num)->setRed();
        btnsLight.at(Num)->setText(msg);
    }
}
void bottomLightButton::setOneIng(int num)
{
    setAllMachineGreen();
    btnsLight.at(num)->setYellow();
}

void bottomLightButton::setLabelInfo(int loc, QString info)
{
    switch (loc) {
    case 1:
        ui->label1->setText(info);
        break;
    case 2:
        ui->label2->setText(info);
        break;
    case 3:
        ui->label3->setText(info);
        break;
    case 4:
        ui->label4->setText(info);
        break;
    case 5:
        ui->label5->setText(info);
        break;
    default:
        break;
    }
}
void bottomLightButton::setLightColorYellow(int loc)
{
    for(int i = 0; i < btnsLight.count(); i++)
    {
        btnsLight.at(i)->setGreen();
    }
    btnsLight.at(loc - 1)->setYellow();
}
void bottomLightButton::setLightColorInit()
{
    for(int i = 0; i < btnsLight.count(); i++)
    {
        btnsLight.at(i)->setGreen();
    }
}
